package com.speaktoitcookbook.dao.proxy;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.List;

import com.speaktoitcookbook.bean.Feedback;
import com.speaktoitcookbook.dao.IFeedbackDao;
import com.speaktoitcookbook.dao.impl.FeedbackDaoImpl;
import com.speaktoitcookbook.db.Database;

/**
 * 用户反馈数据操作代理类
 * 
 * @author 赛艳志
 * 
 */
public class FeedbackDaoProxy implements IFeedbackDao {
    private Connection conn;
    private IFeedbackDao dao;

    public FeedbackDaoProxy() {
        this.conn = Database.getConnection();
        this.dao = new FeedbackDaoImpl(conn);
    }

    @Override
    public boolean doCreate(Feedback feedback) throws SQLException {
        boolean result = false;
        if (null != feedback) {
            try {
                result = dao.doCreate(feedback);
            } catch (SQLException e) {
                throw e;
            } finally {
                Database.close(conn);
            }
        }
        return result;
    }

    @Override
    public boolean doDelete(long ID) throws SQLException {
        boolean result = false;
        if (ID > 0) {
            try {
                result = dao.doDelete(ID);
            } catch (SQLException e) {
                throw e;
            } finally {
                Database.close(conn);
            }
        }
        return result;
    }

    @Override
    public boolean doDelete(Object... params) throws SQLException {
        boolean result = false;
        if (null != params) {
            try {
                result = dao.doDelete(params);
            } catch (SQLException e) {
                throw e;
            } finally {
                Database.close(conn);
            }
        }
        return result;
    }

    @Override
    public boolean doUpdate(Feedback feedback) throws SQLException {
        boolean result = false;
        if (null != feedback) {
            try {
                result = dao.doUpdate(feedback);
            } catch (SQLException e) {
                throw e;
            } finally {
                Database.close(conn);
            }
        }
        return result;
    }

    @Override
    public boolean doUpdate(Object... params) throws SQLException {
        boolean result = false;
        if (null != params) {
            try {
                result = dao.doUpdate(params);
            } catch (SQLException e) {
                throw e;
            } finally {
                Database.close(conn);
            }
        }
        return result;
    }

    @Override
    public Feedback getFeedback(long ID) throws SQLException {
        Feedback result = null;
        if (ID > 0) {
            try {
                result = dao.getFeedback(ID);
            } catch (SQLException e) {
                throw e;
            } finally {
                Database.close(conn);
            }
        }
        return result;
    }

    @Override
    public List<Feedback> getFeedback(Object... params) throws SQLException {
        List<Feedback> result = null;
        if (null != params) {
            try {
                result = dao.getFeedback(params);
            } catch (SQLException e) {
                throw e;
            } finally {
                Database.close(conn);
            }
        }
        return result;
    }
}
